<?php

namespace App\Http\Controllers\WAP\User;

use Illuminate\Http\Request;
use Session;
use App\Http\Requests;
use App\Http\Service\User\UserService;
use App\Http\Controllers\Controller;
use App\Http\Controllers\WAP\ValidateCode\ValidateCodeController;


class RegisterController extends Controller
{
    protected $index = 'WAP.User.register';

    /**
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     * 注册视图
     */
    public function register()
    {
        $title='注册';
        return view($this->index)->with('title',$title);
   }

    /**
     * @param Request $request
     * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\Laravel\Lumen\Http\Redirector|void
     * 执行注册
     */
    public function doRegister(Request $request)
    {


        $where = [];
        $where = $request->except('_token');
        $data['qq'] = '';
        $data['name'] = $where['username'];
        $data['password'] = $where['password'];
        $data['mobile'] = $where['phone'];
        $data['verify_code'] = $where['code'];
        $data['agent_id'] = env('AGENT');

        $code  = md5($where['validateCode'].'niumokeji888');

        if($code != Session::get("VERIFICATION"))
        {
            $return = array(
                'code' => -1,
                'msg' => "非法的验证码",
                'data' => array()
            );
            return response()->json($return);
        }

        $user = new UserService();
        $ret = $user->register($data);

        return $ret;


    }
}
